package com.zeng.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

/**
 * @author zeng
 * @date 2021/08/09 18:55
 */
@Controller
public class LoginController {
    @RequestMapping("/user/login")
    //不加会报错,添加@ResponseBody不会走视图分析器
    public String login(String username, String password, Model model, HttpSession session){
        //具体业务
        //equals和==有区别
        //重定向到指定html
        if(!StringUtils.isEmpty(username) && password.equals("123456")){
            session.setAttribute("loginUser", username);
            return "redirect:/main.html";
        }else {
            //登入失败
            model.addAttribute("msg", "用户名或者密码错误");
            return "redirect:/index.html";
        }
    }
}
